package shell

import (
	"fmt"
)

type InstallStr struct{}

func (is InstallStr) JavaStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "mkdir /usr/java;")
	str = fmt.Sprintf("%s%s", str, "cd /usr/java;")
	str = fmt.Sprintf("%s%s", str, "wget -O jdk-8u212-linux-x64.tar.gz 'http://file.xzdream.cn/file/DownloadFile?path=/java/jdk&name=jdk-8u212-linux-x64.tar.gz';")
	str = fmt.Sprintf("%s%s", str, "cd /usr/java;")
	str = fmt.Sprintf("%s%s", str, "tar -zxf jdk-8u212-linux-x64.tar.gz;")
	str = fmt.Sprintf("%s%s", str, "chown -R root:root jdk1.8.0_212/;")
	str = fmt.Sprintf("%s%s", str, "chown -R root:root jdk1.8.0_212/*;")
	str = fmt.Sprintf("%s%s", str, "echo 'JAVA_HOME=/usr/java/jdk1.8.0_212' >> /etc/profile;")
	str = fmt.Sprintf("%s%s", str, "echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile;")
	str = fmt.Sprintf("%s%s", str, "source /etc/profile;")
	return str
}

func (is InstallStr) SshStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "cd ~;")
	str = fmt.Sprintf("%s%s", str, "ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa >> a.txt;")
	str = fmt.Sprintf("%s%s", str, "cd .ssh/;")
	str = fmt.Sprintf("%s%s", str, "cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys;")
	str = fmt.Sprintf("%s%s", str, "chmod 600 authorized_keys;")
	//str = fmt.Sprintf("%s%s", str, "echo '127.0.0.1 hadoop001 hadoop001' >> /etc/hosts;")
	return str
}

func (is InstallStr) HadoopStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "echo 'HADOOP_HOME=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0' >> /etc/profile;")
	str = fmt.Sprintf("%s%s", str, "echo 'export PATH=$HADOOP_HOME/bin:$PATH' >> /etc/profile;")
	str = fmt.Sprintf("%s%s", str, "cd ~;")
	str = fmt.Sprintf("%s%s", str, "mkdir software;cd software;")
	str = fmt.Sprintf("%s%s", str, "groupadd hadoop;")
	str = fmt.Sprintf("%s%s", str, "useradd -g hadoop hadoop;")
	str = fmt.Sprintf("%s%s", str, "mkdir -p /home/hadoop/app/;")
	str = fmt.Sprintf("%s%s", str, "wget -O hadoop-2.6.0-cdh5.7.0.tar.gz 'http://file.xzdream.cn/file/DownloadFile?path=/hadoop&name=hadoop-2.6.0-cdh5.7.0.tar.gz';")
	str = fmt.Sprintf("%s%s", str, "tar -zxf hadoop-2.6.0-cdh5.7.0.tar.gz -C /home/hadoop/app/;")
	str = fmt.Sprintf("%s%s", str, "sed -i '25d' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;")

	str = fmt.Sprintf("%s%s", str, "sed -i '24a export JAVA_HOME=/usr/java/jdk1.8.0_212' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;")
	str = fmt.Sprintf("%s%s", str, "sed -i '25a export HADOOP_PREFIX=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;")

	str = fmt.Sprintf("%s%s", str, "sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '20a <name>fs.defaultFS</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '21a <value>hdfs://hadoop001:9000</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;")

	str = fmt.Sprintf("%s%s", str, "sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '20a <name>dfs.replication</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '21a <value>1</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '23a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '24a <name>dfs.namenode.secondary.http-address</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '25a <value>hadoop001:50090</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '26a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '27a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '28a <name>dfs.namenode.secondary.https-address</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '29a <value>hadoop001:50091</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '30a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;")

	str = fmt.Sprintf("%s%s", str, "sed -i 's/localhost/hadoop001/g' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/slaves;")

	str = fmt.Sprintf("%s%s", str, "cp /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml.template /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '20a <name>mapreduce.framework.name</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '21a <value>yarn</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;")

	str = fmt.Sprintf("%s%s", str, "sed -i '17a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '18a <name>yarn.nodemanager.aux-services</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '19a <value>mapreduce_shuffle</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;")
	str = fmt.Sprintf("%s%s", str, "sed -i '20a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;")

	str = fmt.Sprintf("%s%s", str, "/home/hadoop/app/hadoop-2.6.0-cdh5.7.0/bin/hdfs namenode -format >> /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/bin/format.log;")

	str = fmt.Sprintf("%s%s", str, "yum -y install expect >> yum.log;")
	str = fmt.Sprintf("%s%s", str, "cd /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/sbin;")
	str = fmt.Sprintf("%s%s", str, "wget -O start_hadoop-2.6.0-cdh5.7.0.sh 'http://file.xzdream.cn/file/DownloadFile?path=/hadoop&name=start_hadoop-2.6.0-cdh5.7.0.sh';")
	str = fmt.Sprintf("%s%s", str, "chmod +x start_hadoop-2.6.0-cdh5.7.0.sh;")
	str = fmt.Sprintf("%s%s", str, "/home/hadoop/app/hadoop-2.6.0-cdh5.7.0/sbin/start_hadoop-2.6.0-cdh5.7.0.sh >> hadoop.log;")

	return str
}

func (is InstallStr) NginxStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "cd ~;")
	str = fmt.Sprintf("%s%s", str, "yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel gcc >> yum.log;")
	str = fmt.Sprintf("%s%s", str, "wget -O nginx-1.12.2.tar.gz 'http://file.xzdream.cn/file/DownloadFile?path=/nginx&name=nginx-1.12.2.tar.gz';")
	str = fmt.Sprintf("%s%s", str, "tar -zxf nginx-1.12.2.tar.gz;")
	str = fmt.Sprintf("%s%s", str, "mkdir /usr/local/nginx;")
	str = fmt.Sprintf("%s%s", str, "cd /root/nginx-1.12.2;")
	str = fmt.Sprintf("%s%s", str, "./configure --prefix=/usr/local/nginx/ >> nginx.log;")
	str = fmt.Sprintf("%s%s", str, "make && make install >> nginx.log;")
	str = fmt.Sprintf("%s%s", str, "cd /usr/local/nginx;")
	str = fmt.Sprintf("%s%s", str, "ls -l;")
	return str
}

//安装编译好的nginx
func (is InstallStr) NginxSbinStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "cd ~;")
	str = fmt.Sprintf("%s%s", str, "wget -O nginx-1.12.2.tar.gz 'http://file.xzdream.cn/file/DownloadFile?path=/nginx&name=nginx-1.12.2-sbin.tar.gz';")
	str = fmt.Sprintf("%s%s", str, "mkdir /usr/local/nginx;")
	str = fmt.Sprintf("%s%s", str, "tar -zxf nginx-1.12.2.tar.gz -C /usr/local;")
	str = fmt.Sprintf("%s%s", str, "cd /usr/local/nginx;")
	str = fmt.Sprintf("%s%s", str, "ls -l;")
	return str
}

func (is InstallStr) RedisStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel gcc >> yum.log;")
	str = fmt.Sprintf("%s%s", str, "cd ~;wget -O redis-6.2.6.tar.gz 'http://file.xzdream.cn/file/DownloadFile?path=/redis&name=redis-6.2.6.tar.gz';")
	str = fmt.Sprintf("%s%s", str, "tar -zxf redis-6.2.6.tar.gz -C /usr/local;")
	str = fmt.Sprintf("%s%s", str, "cd /usr/local/redis-6.2.6;make distclean >> /usr/local/redis-6.2.6/redis.log && make >> /usr/local/redis-6.2.6/redis.log;")
	return str
}

func (is InstallStr) MavenStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "cd ~;wget -O apache-maven-3.8.4-bin.tar.gz 'http://file.xzdream.cn/file/DownloadFile?path=/maven&name=apache-maven-3.8.4-bin.tar.gz';")
	str = fmt.Sprintf("%s%s", str, "tar -zxf apache-maven-3.8.4-bin.tar.gz -C /usr/local;")
	str = fmt.Sprintf("%s%s", str, "echo 'MAVEN_HOME=/usr/local/apache-maven-3.8.4' >> /etc/profile;")
	str = fmt.Sprintf("%s%s", str, "echo 'export PATH=$MAVEN_HOME/bin:$PATH' >> /etc/profile;")
	str = fmt.Sprintf("%s%s", str, "source /etc/profile;")
	return str
}

func (is InstallStr) ScalaStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "cd ~;wget -O scala-2.13.7.tgz 'http://file.xzdream.cn/file/DownloadFile?path=/scala&name=scala-2.13.7.tgz';")
	str = fmt.Sprintf("%s%s", str, "tar -zxf scala-2.13.7.tgz -C /usr/local;")
	str = fmt.Sprintf("%s%s", str, "echo 'SCALA_HOME=/usr/local/scala-2.13.7' >> /etc/profile;")
	str = fmt.Sprintf("%s%s", str, "echo 'export PATH=$SCALA_HOME/bin:$PATH' >> /etc/profile;")
	str = fmt.Sprintf("%s%s", str, "source /etc/profile;")
	return str
}

func (is InstallStr) KafkaStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "cd ~;wget -O kafka_2.13-3.0.0.tgz 'http://file.xzdream.cn/file/DownloadFile?path=/kafka&name=kafka_2.13-3.0.0.tgz';")
	str = fmt.Sprintf("%s%s", str, "tar -zxf kafka_2.13-3.0.0.tgz -C /usr/local;")
	return str
}

func (is InstallStr) SparkStr() string {
	str := ""
	str = fmt.Sprintf("%s%s", str, "cd ~;wget -O spark-2.2.0-bin-2.6.0-cdh5.7.0.tgz 'http://file.xzdream.cn/file/DownloadFile?path=/spark&name=spark-2.2.0-bin-2.6.0-cdh5.7.0.tgz';")
	str = fmt.Sprintf("%s%s", str, "tar -zxf spark-2.2.0-bin-2.6.0-cdh5.7.0.tgz -C /usr/local;")
	return str
}
